<template>
  <div>
    <el-card class="box-card" @click="handleClick(1)">
      <template #header>
        <div class="card-header">
          <div @click.stop="handleClick(3)" v-if="choices">
            <el-checkbox style="width: 100%;" @change="change"  v-model="checked2">选择</el-checkbox>
          </div>
          
          <div v-if="!choices">
            <el-text v-if="dataobjs.status == 1" class="mx-1" type="warning"
              >未核校</el-text
            >

            <el-text v-if="dataobjs.status == 2" class="mx-1" type="primary"
              >已核校</el-text
            >
            <el-text v-if="dataobjs.status == 3" class="mx-1" type="danger"
              >已驳回</el-text
            >
            <el-text v-if="dataobjs.status == 4" class="mx-1" type="success"
              >已通过</el-text
            >
            <el-text v-if="dataobjs.status == 5" class="mx-1" type="danger"
              >问题校</el-text
            >
          </div>
          <div v-if="!choices" @click.stop="handleClick(2)">
            <el-dropdown @command="handleCommand" trigger="click" v-if="is_operation" >
            <span class="el-dropdown-link">
              操作<el-icon class="el-icon--right"><arrow-down /></el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                
                <el-dropdown-item command="f" @click="openOk(dataobjs)"  v-if="authority([3])&&dataobjs.is_status=='未排课'">确认排课</el-dropdown-item>

                <el-dropdown-item command="f" @click="handleEdit('edit')"  v-if="authority([2])&&dataobjs.status==3">重新核校</el-dropdown-item>
                <el-dropdown-item command="f" @click="openOkAllons"  v-if="authority([4])&&dataobjs.status==3">重新核校</el-dropdown-item>

                <el-dropdown-item command="c" @click="Problem"  v-if="authority([2])&&(dataobjs.status==1||dataobjs.status==2)">问题校</el-dropdown-item>

                <el-dropdown-item command="d" @click="openOkAll(1,dataobjs.id)"  v-if="authority([2])&&dataobjs.status==2">通过</el-dropdown-item>
                <el-dropdown-item command="e" @click="openOkAll(2,dataobjs.id)"  v-if="authority([2])&&dataobjs.status==2">驳回</el-dropdown-item>

                <el-dropdown-item command="c" @click="handleEdit('edit')"  v-if="authority([4])&&dataobjs.status==1">核校确认</el-dropdown-item>

                <el-dropdown-item command="a" @click="handleEdit('edit')" v-if="authority([2])&&(dataobjs.status!=2&&dataobjs.status!=3&&dataobjs.status!=5)">编辑</el-dropdown-item>

                <el-dropdown-item command="b" @click="handleEdit('delete')" v-if="authority([2])">删除</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          </div>
          
        </div>
      </template>
      <div>
        <div class="text_item">
          <span class="text_1"
            >区域：{{ dataobjs.province }}{{ dataobjs.city }}{{ dataobjs.county }}(区/县)</span
          >
        </div>
        <div class="text_item">
          <span class="text_1">学校：{{ dataobjs.school_name }}</span>
        </div>
        <div class="text_item">
          <span class="text_1"
            >年级和班级：{{ dataobjs.grade }}{{ dataobjs.class_name }}</span
          >
        </div>
        <div class="text_item">
          <span class="text_1"
            >课程：{{ dataobjs.grade }}{{ dataobjs.course }}</span
          >
        </div> 
        <slot>
          
        </slot>
      </div>

      <div class="clearfix">
        <!-- <el-link type="info">{{ formatDateTime(item.updatetime) }}</el-link> -->

        <!-- <div>
            <el-link
              type="primary"
              style="margin-right: 10px"
              @click="handleEdit(item, 'edit')"
              >编辑</el-link
            >
            <el-link type="danger" @click="handleEdit(item, 'delete')"
              >删除</el-link
            >
          </div> -->
      </div>
      <template #footer  >
        <div class="card-footer">
          {{ dataobjs.createtime }}
        </div>
        </template>
    </el-card>
  </div>
</template>

<script>
import { setStorage, getStorage } from "@/utils/util";
import { useRouter, useRoute } from "vue-router";

export default {
  props: {
    // 是否开启多选
    choices: { 
      typeof: Boolean,
        default: false
    },
    dataobjs: {
      typeof: Object,
      default: {},
    },
    is_operation:{
        typeof: Boolean,
        default: false
    }
  },
  data() {
    return {
      
      checked2:false,//当前选择
      userInfo:''
    };
  },
  created() {
    this.userInfo = Number(JSON.parse(getStorage("groupId"))); //权限
 
  },
  methods: {
    Problem(){
      this.$emit('Problem',this.dataobjs)
    },
    authority(groupArr = [0]) {
      // 权限筛选
      let userInfo = this.userInfo;
      // 当前权限和传来的权限组进行对比
      if (groupArr.some((item) => Number(item) === userInfo)) return true;
      return false;
    },
    change(e){
      // 选择的值发生变化
      //console.log(e,'------1')
      this.$emit('inspect',e,this.dataobjs.id)
      // this.$emit('change',this.checked2)
    },
    handleClick(i){
      if(this.choices) return

      if(i==1){
        this.$router.push({path:`/h5_school_details`,query:{id:this.dataobjs.id}})
      }
      if(i==2){
        //console.log('点击操作',i)
      }
      if(i==3){
        // this.checked2 = !this.checked2
        //console.log('点击选择')
      }
    },
    openOkAllons(e){
      this.$emit('openOkAllons',this.dataobjs.id)
    },
    handleEdit(i){
      // 删除
      this.$emit('handleEdit',this.dataobjs,i)
    },
    openOkAll(i,id){
      // 驳回和通过
      this.$emit('openOkAll',i,id)
    },
    openOk(obj){
      // 确认排课
      this.$emit('openOk',obj)

    }
  }
};
</script>

<style>
.card-header {
  display: flex;
  justify-content: space-between; 
}
.text_item {
  line-height: 24px !important;
  font-size: 14px !important;
}
.clearfix {
  display: flex;
  justify-content: space-between;
  width: 100%;
  align-items: center;
  padding-top: 10px;
  font-size: 14px;
}
.card-footer{
  font-size: 13px;
}
</style>
